USE [texchange_db]
GO

/****** Object:  UserDefinedFunction [dbo].[Fn_GetAllCust]    Script Date: 05/29/2011 19:54:16 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[Fn_GetAllCust] 
(	
	-- Add the parameters for the function here
	@start  bigint=0,
	@limit bigint=30,
	@order nvarchar(10) = 'id',
	@orderdir nvarchar(4) = 'desc'
)
RETURNS TABLE 
AS
RETURN 
(
	-- Add the SELECT statement with parameter references here
	SELECT [id],[name],[email] from
			(SELECT id, name, email, ROW_NUMBER() OVER (ORDER BY @order asc) AS  rownum FROM Company) as a
		WHERE rownum >=@start AND rownum<=@limit
)

GO


